/*************************************************************************
	> File Name: 032.HZOJ-674.宿舍楼里的电竞赛.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  6/29 18:18:49 2021
 ************************************************************************/

#include <iostream>
#include <cstring>
using namespace std;

int n, m, arr[105][105], in_degree[105], out_degree[105], ans;

int main() {
    memset(arr, 0x3f, sizeof(arr));
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        arr[a][b] = 1;
    }

    //Floyd算法
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                arr[j][k] = min(arr[j][k], arr[j][i] + arr[i][k]);
            }
        }
    }

    //遍历邻接矩阵
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (arr[i][j] != 0x3f3f3f3f) {
                out_degree[i]++;
                in_degree[j]++;
            }
        }
    }

    //判断每个点的入度和出度之和
    for (int i = 1; i <= n; i++) {
        if (in_degree[i] + out_degree[i] == n - 1) {
            ans++;
            //cout << i << " : " << in_degree[i] + 1 << endl; //每支队伍的排名
        }
    }

    cout << ans << endl;

    return 0;
}
